/*
 * @Author: szx
 * @Date: 2021-12-25 13:41:05
 * @LastEditTime: 2021-12-25 13:51:55
 * @Description:
 * @FilePath: \leetcode\200-299\236\236.js
 */
/**
 * @param {TreeNode} root
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {TreeNode}
 */
 var lowestCommonAncestor = function (root, p, q) {
    if (root == p || root == q || root == null) return root;
    const resLeft = lowestCommonAncestor(root.left,p,q);
    const resRight = lowestCommonAncestor(root.right,p,q);
    if (resLeft && resRight) return root;
    if (resLeft) return resLeft;
    if (resRight) return resRight;
    return null;
};